package com.draemoncode.weixindb.action;

import com.draemoncode.weixindb.constant.MessagePackageTypeConstant;
import com.draemoncode.weixindb.constant.ShowMessageConstant;
import com.draemoncode.weixindb.domain.B_Member;
import com.draemoncode.weixindb.repository.B_MemberRepository;
import com.draemoncode.weixindb.server.CMessagePackage;
import com.draemoncode.weixindb.server.IAction;
import com.draemoncode.weixindb.service.BusiService;
import com.draemoncode.weixindb.util.ValueUtil;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Component;

import java.util.List;

/**
 *
 * @author yangz
 * @date 2017/4/9
 *
 */
@Component
public class ShowAccountAction implements IAction<List<B_Member>, Object>{

    public final static String ACTION = "showAccount";

    @Autowired
    private B_MemberRepository b_memberRepository;

    @Autowired
    private BusiService busiService;

    @Override
    public Boolean shoudProcess(String action) {
        return ACTION.equals(action);
    }

    @Override
    public List<B_Member> busiExec() {
        return b_memberRepository.findAll();
    }

    @Override
    public Object uiExec(List<B_Member> busiResult) {
        return null;
    }

    @Override
    public CMessagePackage buildResponse(List<B_Member> busiResult, Object uiResult) {
        CMessagePackage response = new CMessagePackage(MessagePackageTypeConstant.RESPONSE_SHOW);
        StringBuilder sb = new StringBuilder();
        sb.append("--------土豪榜--------\n");
        for (B_Member b_member : busiResult) {
            sb.append("[ " + b_member.getName() + " ]").append(" : ").append(ValueUtil.formatMoney(b_member.getMoney())).append("\n");
        }
        response.setSyncid(0);
        response.getMsg().put(ShowMessageConstant.RESPONSE_SHOW_CONTENT, sb.toString());
        return response;
    }
}
